#include "header.h"

int extract_header(char *buffer)
{
  int ret = 0;

  if (buffer[0] == '1')
    ret = COM_SEND_FILE;
  else if (buffer[0] == '2')
    ret = COM_SEND_IP;
  else if (buffer[0] == '3')
    ret = COM_RET_IP;

  strncpy(buffer, buffer + 2, 1022);

  return ret;
}

char *extract_fheader(char *buffer)
{
  char *filename = NULL;
  int pos = 0;
  int pos2 = 0;
  int i = 0;

  while (buffer[pos] != '\'')
    {
      pos++;
    }
  filename = malloc(pos);
  strncpy(filename, buffer, pos);
  while(filename[i] != '\0')
    {
      if (filename[i] == '/')
	pos2 = i;
      i++;
    }
  strncpy(filename, filename + pos2 + 1, strlen(filename) - pos2);
  filename[pos2 + 1] = '\0';
  strncpy(buffer, buffer + pos, strlen(buffer) - pos);
  return filename;
}
